package cmdServer

import (
	"bufio"
	"encoding/base64"
	"fmt"
	"net"
	"os"
	"path/filepath"
	"remote-go/server/data"
	"remote-go/server/util"
	"remote-go/utils"
	"strings"
)

func SendScreenShot(ok bool, _conn net.Conn) {
	if ok {
		encScreenShot := base64.URLEncoding.EncodeToString([]byte("screenshot"))
		_conn.Write([]byte(encScreenShot + "\n"))
	} else {
		fmt.Println("请重新选择客户端, help查看帮助")
	}
}
func AcceptScreenShot(clientIp string, conn net.Conn) {
	encData, _ := bufio.NewReader(conn).ReadString('\n')
	fmt.Println(data.YELLOW, "-> Getting ScreenShot...")
	decData, _ := base64.URLEncoding.DecodeString(encData)
	pngName := strings.Replace(clientIp, ":", "_", -1) + "_" + util.GetDateTime() + ".png"
	absFilePath, _ := filepath.Abs(filepath.Join("temp", pngName))
	utils.CreateBaseDir(absFilePath)
	os.WriteFile(absFilePath, decData, 777)
	fmt.Printf(data.GREEN+"-> ScreenShot Done, filename: %s\n", absFilePath)
}
